﻿using System.Collections.Generic;
using UcAsp.Net.IDAL;
using UcAsp.Net.Model;
using System.Linq;
namespace UcAsp.Net.BLL
{
    public class DefinedCodeBLL
    {
        
        private static readonly IDefinedCodeDAL dal = DALFactory.DataAccess.CreateDefinedCode();
        public List<UcAsp.Net.Model.DefinedCode> Select()
        {
            if (Comm.SpaceCache.GetCache("DefinedCode") != null)
            { 
                Comm.SpaceCache.CreateCache(dal.Select(),"DefinedCode");
            }
            return (List<UcAsp.Net.Model.DefinedCode>)Comm.SpaceCache.GetCache("DefinedCode");
           
        }
        public List<UcAsp.Net.Model.DefinedCode> Select(int pagesize, int pageindex, out int pagecount)
        {
            return dal.Select(pagesize, pageindex, out pagecount);
        }
        public bool Update(UcAsp.Net.Model.DefinedCode code)
        {
            return dal.Update(code);
        }
        public bool Insert(UcAsp.Net.Model.DefinedCode code)
        {
            return dal.Insert(code);
        }
        public bool Delete(UcAsp.Net.Model.DefinedCode code)
        { return dal.Delete(code); }
        public UcAsp.Net.Model.DefinedCode GetDefinedCodeName(int id)
        {
            return dal.GetDefinedCodeName(id);
        }

        public static UcAsp.Net.Model.DefinedCode DefinedCodeName(int id)
        {
            return new DefinedCodeBLL().GetDefinedCodeName(id);
        }
        public static List<UcAsp.Net.Model.DefinedCode> DefinedCodeName(string definedcodetype)
        {
            return new DefinedCodeBLL().Select().Where(o => o.DefinedCodeType.Equals(definedcodetype)).OrderByDescending(o=>o.DisplayRank).ToList();
        }
    }
}
